package com.beikai.demo01;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class Demo01Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo01Application.class, args);
    }

    @Autowired
    private RedissonClient redissonClient;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    private void test() throws InterruptedException {
        RLock lock = redissonClient.getLock("");
        lock.tryLock(1, TimeUnit.SECONDS);
        try {

        }finally {
            lock.unlock();
        }
    }

}
